<template>
    <div class="components-container">
        <!-- <div class="header-form" style="margin-bottom:0px;">
          <div class="layui-inline">
            <label class="layui-form-label">开始日期</label>
            <div class="layui-input-inline backcolor">
              <el-date-picker v-date v-model="selectDataExtend.RegcremationdateGreaterAndEquals" type="date"></el-date-picker>
            </div>
          </div>
          <div class="layui-inline">
            <label class="layui-form-label">结束日期</label>
            <div class="layui-input-inline backcolor">
              <el-date-picker v-date v-model="selectDataExtend.RegcremationdateLessAndEquals" type="date"></el-date-picker>
            </div>
          </div>
          <el-button type="primary" @click="grasps" :loading="this.$store.state.isloading">抓取</el-button>
          <el-button  @click="btnRepeat" >重置</el-button>
        </div> -->
        <div style="height:56px">
            <ul class="toolList">
                <li>
                  <el-button type="primary" @click="btnSearch" :loading="this.$store.state.isloading">刷新</el-button>
                </li>
                <li v-if="btnShow(item.BTNVALUE)" v-for="(item, index) in $store.state.btnListCommon" @click="operate(item.BTNVALUE)">
                  <el-button type="primary" :value="item.BTNSHOWNAME" v-text="item.BTNSHOWNAME" :disabled="$store.state.isloading"></el-button>
                </li>
            </ul>
        </div>
        <dataTable :headList="headList" :dataList="dataList" :pageOrder="pageOrder" :clounmnames="clounmnames" :hiddenWarn="hiddenWarn" @pageChange="pageChange" @selectRow="selectRow"></dataTable>
        <dataReportMain ref="dataReportMain" @refreshData="btnsearch"></dataReportMain>
        <sweet-modal ref="info" class="dialog" :sweetModalMaxWidth="pageWidth">
          <h3>数据抓取</h3>
          <div style="margin:10px 20px">
            <div class="layui-form-item">
              <div class="layui-inline">
                <label class="layui-form-label">开始日期</label>
                <div class="layui-input-inline backcolor">
                  <el-date-picker v-date v-model="selectDataExtend.RegcremationdateGreaterAndEquals" type="date"></el-date-picker>
                </div>
              </div>
              <div class="layui-inline">
                <label class="layui-form-label">结束日期</label>
                <div class="layui-input-inline backcolor">
                  <el-date-picker v-date v-model="selectDataExtend.RegcremationdateLessAndEquals" type="date"></el-date-picker>
                </div>
              </div>
            </div>
          </div>
          <div class="layui-form-item btnCenter sweet-btn">
            <el-button @click="closeDialog">取消</el-button>
            <el-button @click="grasps" :loading="this.$store.state.isloading">抓取</el-button>
          </div>
        </sweet-modal>
    </div>
    
</template>
<script>
import sweetModal from "@/components/sweetModal";
import dataTable from "@/components/Table/DataTable";
import dataReportMain from "./dataReportMain";
import apiBase from "@/api/apiBase.js";
import { formatDate, timeStringToDate, dateStringToDate } from "@/utils/date.js";
import { manage } from "@/mixins/managePage.js";
import { ORDER } from "@/const/orderConst.js";

const ADD = "新增";
const MODIFY = "修改";
const GRASP = "抓取";
const REPORT = "上报";
const DELETE = "删除";
const INFO = "详情";


export default {
  name: "cost",
  mixins: [manage],
  data() {
    return {
      pageWidth: 1200,
      maxHeight: 500,
      selectDataExtend: {
        RegcremationdateGreaterAndEquals: null,
        RegcremationdateLessAndEquals: null,
      },
      //费用信息
      cotData: {},
      hiddenWarn: true,//控制是否显示提醒栏
      clounmnames: '是否警告',//控制警告栏的表头
    };
  },
  methods: {
    btnsearch() {
      this.getData();
    },
    //获取表头
    getColumns() {
      let data = {};
      apiBase.DoService(
        data,
        apiBase.getApiAdress().Column.GetDatareportColumns,
        res => {
          this.headList = res.data.content;
        }
      );
    },
    //获取费用信息
    getData() {
      let data = {
        PageIndex: this.pageOrder.currentPage,
        PageSize: this.pageOrder.pageSize,
        OrderBy: this.pageOrder.orderType,
        OrderByType: this.pageOrder.orderSort,
        Data: this.selectData
      };
      apiBase.DoService(data, apiBase.getApiAdress().DataReport.Query, res => {
        this.dataList = res.data.content.OutData;
        this.pageOrder.totalNum = res.data.content.RecordCount;
      });
    },
                //删除派车记录
    deleteCotInfo(cotid) {
      this.$confirm("此操作将永久删除该费用信息, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
        }).then(callback => 
         {
           var data = {
           COTID: cotid
          };
          apiBase.DoService(data, apiBase.getApiAdress().Cost.Delete, res => {
          this.getData();
            });
          });
    },
    grasps(){
      // let datas = JSON.parse(JSON.stringify(this.selectDataExtend));;
      // datas.RegcremationdateGreaterAndEquals = formatDate(this.selectDataExtend.RegcremationdateGreaterAndEquals,"yyyyMMdd");
      // datas.RegcremationdateLessAndEquals = formatDate(this.selectDataExtend.RegcremationdateLessAndEquals,"yyyyMMdd");
      this.$store.state.isloading = true;
      let data = {
        PageIndex: this.pageOrder.currentPage,
        PageSize: this.pageOrder.pageSize,
        OrderBy: this.pageOrder.orderType,
        OrderByType: this.pageOrder.orderSort,
        // Data: datas
        RegcremationdateGreaterAndEquals: formatDate(this.selectDataExtend.RegcremationdateGreaterAndEquals,"yyyyMMdd"),
        RegcremationdateLessAndEquals: formatDate(this.selectDataExtend.RegcremationdateLessAndEquals,"yyyyMMdd"),
      };
      apiBase.DoService(data, apiBase.getApiAdress().DataReport.Grasp, 
        res => {
          this.$refs.info.close();
          this.$message({
            type: "success",
            message: "抓取成功!"
          });
          setTimeout(() => {
            this.getData();
          }, 1500);
        },
        // res => {
        //   this.$refs.info.close();
        //   setTimeout(() => {
        //     this.getData();
        //   }, 1500);
        // }
      );
    },
    //功能操作
    operate(order) {
      this.order = order
      switch(this.order){
        case '提取':
          this.GetDataReportStartDate();
          // this.selectDataExtend.RegcremationdateGreaterAndEquals = new Date();
          this.selectDataExtend.RegcremationdateLessAndEquals = new Date((new Date()).getTime() + 24*60*60*1000);
          this.$refs.info.open();
        break;
        case '新增':
          this.$refs.dataReportMain.open('新增');
        break;
        case '修改':
          this.$refs.dataReportMain.open('修改',this.currentRow.REGID);
        break;
        case '详情':
          this.$refs.dataReportMain.open('详情',this.currentRow.REGID);
        break;
        case '删除':
          this.Delete();
        break;
        case '上报':
          this.$store.state.isloading = true;
          this.Report();
        break;
        default:
      }
    },
    //上报
    Report(){
      // console.log(this.dataList);
      // let list_Reg = [];
      // for(var i = 0;i < this.dataList.length;i++){
      //   if(this.dataList[i].REGID){
      //     list_Reg.push({REGID:this.dataList[i].REGID});
      //   }
      // }
      // console.log(list_Reg);
      let data = {
        // list_Reg: list_Reg
      };
      apiBase.DoService (
        data,
        apiBase.getApiAdress().DataReport.Report,
        res => {
          setTimeout(() => {
            this.getData();
          }, 1500);
          this.$message({
            type: "success",
            message: "上报成功!"
          });
        }
      );
    },
    //数据上报开始时间
    GetDataReportStartDate(){
      let data = {};
      apiBase.DoService (
        data,
        apiBase.getApiAdress().Param.GetDataReportStartDate,
        res => {
          console.log(res.data.content);
          this.selectDataExtend.RegcremationdateGreaterAndEquals = dateStringToDate(
            res.data.content
          );
        }
      );
    },
     //删除
    Delete() {
      this.$confirm("确认是否删除该数据?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
      })
        .then(callback => {
            let data = {
                REGID: this.currentRow.REGID
            };
            apiBase.DoService(
                data,
                apiBase.getApiAdress().DataReport.Delete,
                res => {
                    this.getData();
                }
            );
        })
        .catch(() => {
            this.$message({
                type: "info",
                message: "已取消"
            });
        });
    },
    closeDialog(){
      this.$refs.info.close();
    },
    //打开子页面
    openWindow(order,id) {
     if(order==ADD)
     {
        // this.$refs.costAdd.open(ORDER.ADD,null);
        return;
     }
     else 
     {  let pageOrder;
        if(order==MODIFY)
         pageOrder=ORDER.MODIFY;
        else if(order==INFO)
         pageOrder=ORDER.INFO;
        // this.$refs.costAdd.open(pageOrder, this.currentRow.COTID);
     }
    },
    //查询条件重置
    btnRepeat() {
      this.selectData = {};
      this.initSeachdata();
      this.getData();
    },
    //按钮显隐
    btnShow(btn) {
      if(btn === '新增' || btn === '提取' || btn === '上报') return true;
      if (!this.currentRow) return false;
      if(btn === '修改' || btn === '删除') return true;
      return true;
    },
    //测试打印
    testPrint() {
      console.log(this.$store.state.btnListCommon);
    },
    initSeachdata() {

    }
  },
  components: {
    sweetModal,
    dataTable,
    dataReportMain
  },
  activated() {
    this.getData();
  },
  mounted() {
    this.initSeachdata();
  },
  created() {
    var curDate = new Date();
    // this.selectDataExtend.RegcremationdateGreaterAndEquals = new Date();
    // this.selectDataExtend.RegcremationdateLessAndEquals = new Date();
    this.selectDataExtend.RegcremationdateLessAndEquals = new Date(curDate.getTime() + 24*60*60*1000);
    this.initSeachdata();
    this.getColumns();
  },
};
</script>